package com.example.blog_system.controller;

import com.example.blog_system.dto.ApiResponse;
import com.example.blog_system.repository.UserRepository;
import com.example.blog_system.repository.ArticleRepository;
import com.example.blog_system.repository.CommentRepository;
import com.example.blog_system.repository.TagRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api/statistics")
public class StatisticsController {
    @Autowired
    private UserRepository userRepository;
    @Autowired
    private ArticleRepository articleRepository;
    @Autowired
    private CommentRepository commentRepository;
    @Autowired
    private TagRepository tagRepository;

    @GetMapping("")
    public ApiResponse<Map<String, Long>> getStatistics() {
        Map<String, Long> stats = new HashMap<>();
        stats.put("userCount", userRepository.count());
        stats.put("articleCount", articleRepository.count());
        stats.put("commentCount", commentRepository.count());
        stats.put("tagCount", tagRepository.count());
        return ApiResponse.success("统计数据获取成功", stats);
    }
}